//
//  ModelUserCreditInfo.m
//  MexicoLoan
//
//  Created by wxp on 2025/3/8.
//

#import "ModelUserCreditInfo.h"

NSString *const kModelUserCreditInfoUsed = KEY_used;
NSString *const kModelUserCreditInfoExtraAmountIsNotReminded = KEY_extraAmountIsNotReminded;
NSString *const kModelUserCreditInfoUnused = KEY_unused;
NSString *const kModelUserCreditInfoTotal = KEY_total;
NSString *const kModelUserCreditInfoLocking = KEY_locking;

@interface ModelUserCreditInfo ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ModelUserCreditInfo

@synthesize used = _used;
@synthesize extraAmountIsNotReminded = _extraAmountIsNotReminded;
@synthesize unused = _unused;
@synthesize total = _total;
@synthesize locking = _locking;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if (self && [dict isKindOfClass:[NSDictionary class]]) {
        self.used = [[self objectOrNilForKey:kModelUserCreditInfoUsed fromDictionary:dict] doubleValue];
        self.extraAmountIsNotReminded = [[self objectOrNilForKey:kModelUserCreditInfoExtraAmountIsNotReminded fromDictionary:dict] boolValue];
        self.unused = [[self objectOrNilForKey:kModelUserCreditInfoUnused fromDictionary:dict] doubleValue];
        self.total = [[self objectOrNilForKey:kModelUserCreditInfoTotal fromDictionary:dict] doubleValue];
        self.locking = [[self objectOrNilForKey:kModelUserCreditInfoLocking fromDictionary:dict] doubleValue];
    }
    return self;
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.used] forKey:kModelUserCreditInfoUsed];
    [mutableDict setValue:[NSNumber numberWithBool:self.extraAmountIsNotReminded] forKey:kModelUserCreditInfoExtraAmountIsNotReminded];
    [mutableDict setValue:[NSNumber numberWithDouble:self.unused] forKey:kModelUserCreditInfoUnused];
    [mutableDict setValue:[NSNumber numberWithDouble:self.total] forKey:kModelUserCreditInfoTotal];
    [mutableDict setValue:[NSNumber numberWithDouble:self.locking] forKey:kModelUserCreditInfoLocking];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description  {
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}

@end
